package com.ledi.guns.modular.ledipay.controller;

import io.swagger.annotations.Api;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ledi.guns.common.persistence.model.vo.ApplyCooperateVo;
import com.ledi.guns.common.persistence.model.vo.TaskRecordVo;
import com.ledi.guns.core.base.tips.SuccessTip;
import com.ledi.guns.core.base.tips.Tip;
import com.ledi.guns.modular.ledipay.controller.req.apply.QueryApplyCooperate;
import com.ledi.guns.modular.ledipay.controller.req.apply.TrackApply;
import com.ledi.guns.modular.ledipay.controller.req.workOrder.HandleWorkOrder;
import com.ledi.guns.modular.ledipay.service.ApplyCooperateService;

/**
 * 文件名称： com.ledi.guns.modular.ledipay.controller.ApplyCooperateController.java<br/>
 * 初始作者： 钟小平<br/>
 * 创建日期： 2018年10月8日<br/>
 * 功能说明： 申请合作Controller <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者 日期 修改内容<br/>
 * ================================================<br/>
 * Copyright (乐迪教育科技有限公司-幼儿事业部) 2017-2018.All rights reserved.<br/>
 */
@Api
@RestController
@RequestMapping("/applyCooperate")
public class ApplyCooperateController {

	@Resource
	private ApplyCooperateService applyCooperateService;

	/**
	 * @api {POST} /applyCooperate/list 申请合作列表
	 * @apiGroup applyCooperate
	 * @apiName list
	 * @apiParam {String} type 类型0学校1代理商
	 * @apiParam {String} status 状态名称,状态：1-未处理；2处理中；3已处理
	 * @apiSuccess {Long} id 主键ID
	 * @apiSuccess {String} applyName 联系人姓名
	 * @apiSuccess {String}contactTel 联系电话
	 * @apiSuccess {String} province 省
	 * @apiSuccess {String} city 市
	 * @apiSuccess {int} versionNo 版本号
	 * @apiVersion 1.5.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "asc": true,
	 *                    "condition": "",
	 *                    "current": 1,
	 *                    "limit": 2147483647,
	 *                    "offset": 0,
	 *                    "offsetCurrent": 0,
	 *                    "openSort": true,
	 *                    "orderByField": "",
	 *                    "pages": 1,
	 *                    "records": [
	 *                    {
	 *                    "applyName": "周",
	 *                    "city": "北京市",
	 *                    "contactTel": "17625320526",
	 *                    "createTime": "2018-10-08 15:45:24",
	 *                    "id": 2,
	 *                    "province": "东城区",
	 *                    "status": "未处理",
	 *                    "type": "运营商",
	 *                    "versionNo": 0
	 *                    },
	 *                    {
	 *                    "applyName": "王",
	 *                    "city": "北京市",
	 *                    "contactTel": "17625320526",
	 *                    "createTime": "2018-10-08 15:44:34",
	 *                    "id": 1,
	 *                    "province": "东城区",
	 *                    "status": "未处理",
	 *                    "type": "学校",
	 *                    "versionNo": 0
	 *                    }
	 *                    ],
	 *                    "searchCount": true,
	 *                    "size": 10,
	 *                    "total": 2
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public Tip list(@RequestBody QueryApplyCooperate queryApplyCooperate) {

		queryApplyCooperate.checkOrder(ApplyCooperateVo.class);
		Page<ApplyCooperateVo> page = applyCooperateService.list(new Page<ApplyCooperateVo>(queryApplyCooperate.getPageNo(), queryApplyCooperate.getPageSize()),
				queryApplyCooperate);
		return SuccessTip.buildSuccess(page);
	}

	/**
	 * @api {POST} /applyCooperate/handle 申请处理
	 * @apiGroup applyCooperate
	 * @apiName handle
	 * @apiParam {Long} id 申请ID
	 * @apiParam {int} versionNo 版本号
	 * @apiParam {int} type 1:处理申请 2:关闭申请 3:激活申请
	 * @apiVersion 1.5.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "id": 1,
	 *                  "versionNo":2,
	 *                  "type":1
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "handle", method = RequestMethod.POST)
	public Tip handle(@RequestBody HandleWorkOrder handleWorkOrder) {

		applyCooperateService.handleApply(handleWorkOrder);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {POST} /applyCooperate/addTrackRecord 申请增加跟踪记录
	 * @apiGroup applyCooperate
	 * @apiName addTrackRecord
	 * @apiParam {Long} applyId 申请ID
	 * @apiParam {String} content 跟踪内容
	 * @apiVersion 1.5.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "applyId": 1,
	 *                  "content":"已经跟踪",
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "addTrackRecord", method = RequestMethod.POST)
	public Tip addTrackRecord(@RequestBody @Valid TrackApply trackApply) {

		applyCooperateService.trackApply(trackApply);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {GET} /applyCooperate/getTrackRecord/{id} 申请获取跟踪内容
	 * @apiGroup applyCooperate
	 * @apiName getTrackRecord
	 * @apiParam {Long} id 申请ID
	 * @apiVersion 1.5.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "getTrackRecord/{id}", method = RequestMethod.GET)
	public Tip getTrackRecord(@PathVariable("id") Long id) {

		List<TaskRecordVo> taskRecordVos = applyCooperateService.getApplyRecord(id);
		return SuccessTip.buildSuccess(taskRecordVos);
	}

}
